package com.example.xm.servive.impl;

import com.example.xm.Entity.Commodity;
import com.example.xm.config.PageResult;
import com.example.xm.mapper.CoyMapper;
import com.example.xm.servive.CoyServive;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoyServiveImpl implements CoyServive {
    @Autowired
    CoyMapper coyMapper;

    @Override
    public List<Commodity> getCoy(Commodity commodity) {
        return coyMapper.getCoy(commodity);
    }


    /**
     * 分页
     * */
    @Override
    public PageResult selectPager(int pageNum, int pageSize, Commodity com) {
        //开始分页，指定页码与每页记录数
        PageHelper.startPage(pageNum,pageSize);
        //执行查询，请求会被分页插件拦截
        List<Commodity> students = coyMapper.getCoy(com);
        //返回分页对象与数据
        return PageResult.getPageResult(new PageInfo<Commodity>(students));
    }

    @Override
    public int del(String id) {
        return  coyMapper.del(id);
    }

    @Override
    public Commodity getCoyId(String id) {
        return coyMapper.getCoyId(id);
    }

    @Override
    public int Add(Commodity commodity) {
        return coyMapper.Add(commodity);
    }

    /**添加到购物车*/
    @Override
    public int AddGwc(Commodity commodity) {
        return coyMapper.AddGwc(commodity);
    }

    @Override
    public int Update(Commodity commodity) {
        return coyMapper.Update(commodity);
    }
}
